//
//  ViewController.m
//  Test
//
//  Created by 郑火 on 16/2/9.
//  Copyright © 2016年 zwz. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextView *text_Add;
@property (weak, nonatomic) IBOutlet UITextView *text_Modify;

@property (strong, atomic) NSMutableArray *list_data;
@end

@implementation ViewController
- (IBAction)OnClickSave:(id)sender {
    Note* newNote = [[Note alloc]init];
    
    
    newNote.date = [NSDate date];
    newNote.content = _text_Add.text;
    
    [[NoteDAO sharedManager]create:newNote];
    
}
- (IBAction)OnClickRemove:(id)sender {
    [self loaddata];
    Note * removeNote = _list_data[0];
    [[NoteDAO sharedManager]remove:removeNote];
    
}
- (IBAction)OnClickLoad:(id)sender {
    [self loaddata];
    
}
-(void)loaddata
{
    //_list_data = [[NoteDAO sharedManager]findAll];
    if(_list_data.count == 0)
    {
        NSLog(@"暂无数据");
        return;
    }
    for(Note * tmp in _list_data)
    {
        NSLog(@"时间:%@  \"%@\"", tmp.date, tmp.content);
    }

}
- (IBAction)OnClickModify:(id)sender {
    
    [self loaddata];
    Note * modifyNote = _list_data.lastObject;
    modifyNote.content = _text_Modify.text;
    [[NoteDAO sharedManager]modify:modifyNote];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
